define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user/recharge/index' + location.search,
                    add_url: 'user/recharge/add',
                    edit_url: 'user/recharge/edit',
                    del_url: 'user/recharge/del',
                    multi_url: 'user/recharge/multi',
                    import_url: 'user/recharge/import',
                    table: 'user_recharge',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'order_no', title: __('Order_no'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'money', title: __('Money'), operate: 'LIKE'},
                        {field: 'dou_money', title: __('Dou_money'), operate: 'LIKE'},
                        {field: 'type', title: __('Type'), searchList: {"1":__('Type 1'),"2":__('Type 2'),"3":__('Type 3'),"4":__('Type 4'),"5":__('Type 5')}, formatter: Table.api.formatter.normal},
                        {field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"2":__('Status 2'),"3":__('Status 3')}, formatter: Table.api.formatter.status},
                        {field: 'device_type', title: __('Device_type'), searchList: {"1":__('Device_type 1'),"2":__('Device_type 2')}, formatter: Table.api.formatter.normal},
                        {field: 'notify_num', title: __('Notify_num')},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'pay_time', title: __('Pay_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'user.username', title: __('User.username'), operate: 'LIKE'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
                        buttons: [
                            {
                                name: 'ajax',
                                text: __('手动回调'),
                                title: __('手动回调'),
                                classname: 'btn btn-xs btn-success btn-magic btn-ajax',
                                icon: 'fa fa-magic',
                                //visible属性可以让按钮显示或者隐藏，这里通过判断status = 6就显示，否则就隐藏
                                visible:function(row){
                                    console.log(row)
                                    if(row.status != 2 && row.device_type == 1){
                                        return true
                                    }else{
                                        return false
                                    }
                                },
                                url: 'user/recharge/notifyXnOrder?order_id={ids}',
                                confirm: '确认手动回调',
                                success: function (data, ret) {
                                    Layer.alert(ret.msg);
                                    //如果需要阻止成功提示，则必须使用return false;
                                    // return false;
                                },
                                error: function (data, ret) {
                                    console.log(data, ret);
                                    Layer.alert(ret.msg);
                                    return false;
                                }
                            },
                        ], formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
